home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0089_Min-Max Longs in ASM.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  4KB  |  98 lines

  1.  
  2. UNIT MaxMinL;
  3. (*
  4.   The source code MaxMinL unit is released to the public domain.  No
  5.   rights are reserved.  Phil Nickell.  NSoft Co.
  6.   This Turbo Pascal unit implements five highly optimized assembly
  7.   language functions that provide MAX() and MIN() for unsigned longword
  8.   and signed longintegers, and also a function for an unsigned longword
  9.   compare.  The word functions treat the passed values as unsigned
  10.   values.  The integer functions treat the passed values as signed
  11.   values.  Turbo pascal does not have a LONGWORD data type, but the
  12.   MAXLW() and MINLW() functions treat the passed longint types as
  13.   unsigned words.  Maxlw returns $ffffffff as greater than 0.  Minlw
  14.   returns 0 as less than $ffffffff.
  15. *)
  16. {$r-,S-}
  17. INTERFACE
  18.    FUNCTION  MAXLW (a,b:longint) : Longint;       { max longword }
  19.    FUNCTION  MINLW (a,b:Longint) : Longint;       { min longword }
  20.    FUNCTION  MAXLI (a,b:longint) : Longint;       { max longint }
  21.    function  MINLI (a,b:Longint) : Longint;       { min longint }
  22.    function  LWGT  (a,b:Longint) : Boolean;       { long > unsigned }
  23.  
  24. IMPLEMENTATION
  25. function maxlw(a,b:longint):longint; Assembler; {long word}
  26.   Asm
  27.         les     ax, a            { load longint to es:ax }
  28.         mov     dx, es           { load longint to dx:ax }
  29.         cmp     dx, word ptr b+2 { cmp high words }
  30.         ja      @2               { high word > }
  31.         jb      @1               { high word < }
  32.         cmp     ax, word ptr b   { comp low word }
  33.         jae     @2               { low word >= }
  34.   @1:   les     ax, b
  35.         mov     dx, es           { load int to dx:ax }
  36.   @2:
  37.   End;
  38.  
  39. function minlw(a,b:longint):longint;  Assembler; { longword }
  40.   Asm
  41.         les     ax, a            { load longint to es:ax }
  42.         mov     dx, es           { load longint to dx:ax }
  43.         cmp     dx, word ptr b+2 { cmp high words }
  44.         jb      @2               { high word < }
  45.         ja      @1               { high word > }
  46.         cmp     ax, word ptr b   { comp low word }
  47.         jbe     @2               { low word >= }
  48.   @1:   les     ax, b
  49.         mov     dx, es           { load int to dx:ax }
  50.   @2:
  51.   End;
  52.  
  53. function maxli(a,b:longint):longint; Assembler;
  54.   Asm
  55.         les     ax, a            { load longint to es:ax }
  56.         mov     dx, es           { load longint to dx:ax }
  57.         cmp     dx, word ptr b+2 { cmp high words }
  58.         jg      @2               { high word > }
  59.         jl      @1               { high word < }
  60.         cmp     ax, word ptr b   { comp low word }
  61.         jae     @2               { low word >= }
  62.   @1:   les     ax, b
  63.         mov     dx, es           { load int to dx:ax }
  64.   @2:
  65.   End;
  66.  
  67. function minli(a,b:longint):longint; Assembler;
  68.   Asm
  69.         les     ax, a            { load longint to es:ax }
  70.         mov     dx, es           { load longint to dx:ax }
  71.         cmp     dx, word ptr b+2 { cmp high words }
  72.         jl      @2               { high word < }
  73.         jg      @1               { high word > }
  74.         cmp     ax, word ptr b   { comp low word }
  75.         jbe     @2               { low word >= }
  76.   @1:   les     ax, b
  77.         mov     dx, es           { load int to dx:ax }
  78.   @2:
  79.   End;
  80.  
  81. function lwgt(a,b:longint):boolean;  Assembler; {unsigned longword greater than
  82. }
  83.   Asm
  84.         xor     cx, cx           { cx = 0 = false }
  85.         les     ax, a            { load longint to es:ax }
  86.         mov     dx, es           { load longint to dx:ax }
  87.         cmp     dx, word ptr b+2 { cmp high words }
  88.         jb      @2               { high word < }
  89.         ja      @1               { high word > }
  90.         cmp     ax, word ptr b   { comp low word }
  91.         jbe     @2               { low word <= }
  92.   @1:   inc     cx               { cx = 1 = true }
  93.   @2:   mov     ax, cx           { load result to ax }
  94.   End;
  95.  
  96. BEGIN {INITIALIZATION}
  97. END.
  98.